import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [{
      path: 'index',
      name: 'Index',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/stream',
    component: Layout,
    redirect: '/stream/storeList',
    name: 'Stream',
    meta: { title: '门店管理' },
    alwaysShow: true,
    children: [
      {
        path: 'storeList',
        name: 'StoreList',
        component: () => import('@/views/stream/storeList'),
        meta: { title: '门店列表' }
      },
      {
        path: 'brands',
        name: 'BrandList',
        component: () => import('@/views/stream/brands'),
        meta: { title: '品牌列表' }
      }
    ]
  },
  {
    path: '/storeList',
    component: Layout,
    name: 'Streams',
    redirect: '/stream/storeList',
    meta: { title: '门店列表' },
    hidden: true,
    children: [
      {
        path: 'infoDetails',
        name: 'InfoDetails',
        component: () => import('@/views/stream/storeList/infoDetails'),
        meta: { title: '门店详情' }
      }
    ]
  },
  {
    path: '/commodity',
    component: Layout,
    name: 'Commodity',
    redirect: '/commodity/setmeal',
    meta: { title: '商品管理' },
    alwaysShow: true,
    children: [
      {
        path: 'setmeal',
        name: 'Setmeal',
        component: () => import('@/views/commodity/setmeal'),
        meta: { title: '套餐列表' }
      },
      {
        path: 'variety',
        name: 'Variety',
        component: () => import('@/views/commodity/variety'),
        meta: { title: '菜品列表' }
      },
      {
        path: 'material',
        name: 'Material',
        component: () => import('@/views/commodity/material'),
        meta: { title: '原料列表' }
      },
      {
        path: 'classification',
        name: 'classification',
        component: () => import('@/views/commodity/classification'),
        meta: { title: '分类管理' }
      }
    ]
  },
  {
    path: '/menu',
    component: Layout,
    redirect: '/menu/indexes',
    name: 'Menu',
    meta: { title: '菜单管理' },
    children: [
      {
        path: 'indexes',
        name: 'Indexes',
        component: () => import('@/views/menu'),
        meta: { title: '菜单设置' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/enterprise',
    name: 'System',
    meta: { title: '用户管理' },
    alwaysShow: true,
    children: [
      {
        path: 'enterprise',
        name: 'Enterprise',
        component: () => import('@/views/system/enterprise'),
        meta: { title: '企业列表' }
      },
      {
        path: 'applyList',
        name: 'ApplyList',
        component: () => import('@/views/system/applyList'),
        meta: { title: '申请列表' }
      },
      {
        path: 'users',
        name: 'Users',
        component: () => import('@/views/system/users'),
        meta: { title: '用户列表' }
      }
    ]
  },
  {
    path: '/system/enterprise',
    component: Layout,
    redirect: '/system/enterprise',
    hidden: true,
    meta: { title: '企业列表' },
    children: [
      {
        path: 'info',
        component: () => import('@/views/system/enterprise/info'),
        name: 'Info',
        meta: { title: '企业详情' }
      }
    ]
  },
  {
    path: '/order',
    meta: { title: '订单中心' },
    name: 'Order',
    component: Layout,
    redirect: '/order/orderList',
    alwaysShow: true,
    children: [
      {
        path: 'orderList',
        name: 'orderList',
        component: () => import('@/views/order/orderList'),
        meta: { title: '订单列表' }
      }
    ]
  },
  {
    path: '/aftershaves',
    meta: { title: '售后中心' },
    name: 'Haves',
    component: Layout,
    redirect: '/aftershaves/dataset',
    alwaysShow: true,
    children: [
      {
        path: 'dataset',
        name: 'dataset',
        component: () => import('@/views/aftershaves/dataset'),
        meta: { title: '售后列表' }
      }
    ]
  },
  {
    path: '/dataset',
    component: Layout,
    name: 'dataName',
    redirect: '/aftershaves/dataset',
    meta: { title: '售后列表' },
    hidden: true,
    children: [
      {
        path: 'sales',
        name: 'Sales',
        component: () => import('@/views/aftershaves/dataset/sales'),
        meta: { title: '售后详情' }
      }
    ]
  },
  {
    path: '/activities',
    meta: { title: '活动中心' },
    name: 'Havana',
    component: Layout,
    redirect: '/activities/alfalfa',
    alwaysShow: true,
    children: [
      {
        path: 'alfalfa',
        name: 'Alfalfa',
        component: () => import('@/views/activities/alfalfa'),
        meta: { title: '活动列表' }
      }
    ]
  },
  {
    path: '/alfalfa',
    component: Layout,
    name: 'informs',
    redirect: '/activities/alfalfa',
    meta: { title: '活动列表' },
    hidden: true,
    children: [
      {
        path: 'into',
        name: 'Into',
        component: () => import('@/views/activities/alfalfa/into'),
        meta: { title: '活动详情' }
      }
    ]
  },
  {
    path: '/datacenter',
    meta: { title: '数据中心' },
    name: 'Have',
    component: Layout,
    redirect: '/datacenter/index',
    alwaysShow: true,
    children: [
      {
        path: 'detained',
        name: 'Detained',
        component: () => import('@/views/datacenter'),
        meta: { title: '数据分布' }
      }
    ]
  },
  {
    path: '/orderList',
    component: Layout,
    name: 'Orders',
    redirect: '/order/orderList',
    hidden: true,
    meta: { title: '订单列表' },
    children: [
      {
        path: 'infos',
        component: () => import('@/views/order/orderList/infos'),
        name: 'Infos',
        meta: { title: '订单详情' }
      }
    ]
  },
  {
    path: '/evaluate',
    meta: { title: '评价中心' },
    component: Layout,
    redirect: '/evaluate/orderEvaluation',
    alwaysShow: true,
    children: [
      {
        path: 'orderEvaluation',
        name: 'OrderEvaluation',
        component: () => import('@/views/evaluate/orderEvaluation'),
        meta: { title: '订单评价' }
      },
      {
        path: 'dishesEvaluation',
        name: 'DishesEvaluation',
        component: () => import('@/views/evaluate/dishesEvaluation'),
        meta: { title: '菜品评价' }
      },
      {
        path: 'opinion',
        name: 'Opinion',
        component: () => import('@/views/evaluate/opinion'),
        meta: { title: '意见与建议' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
